package org.fuys.etp.endpoint;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.fuys.etp.core.EtpCollector;
import org.fuys.etp.core.EtpManager;
import org.fuys.etp.repo.EtpRepoService;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @projectName: fuys-etp-final
 * @package: org.fuys.etp.endpoint
 * @className: EtpStatusEndpoint
 * @author: WangJing
 * @description: 弹性线程池终端
 * @date: 2025/2/24 11:33
 * @version: 1.0
 */
@Endpoint(id = "fuys-etp-status")
@Component
public class EtpStatusEndpoint {

    @Resource
    private EtpCollector etpCollector;

    private ObjectMapper objectMapper = new ObjectMapper();

    @ReadOperation
    public String getPoolMetrics() {
        try {
            return objectMapper.writeValueAsString(etpCollector.getAllPoolMetrics());
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return "{\"error\":\"" + e.getMessage() + "\"}";
        }
    }

}
